package com.example.teacher.Controller;

import com.example.teacher.dao.TeacherMapper;
import com.example.teacher.pojo.Teacher;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Controller
@RequestMapping("/teacher")
public class TeacherController {
    @Autowired
    TeacherMapper teacherMapper;

    @RequestMapping("/sel")
    public String List(ModelMap map){
        List<Teacher> sel = teacherMapper.sel();
        map.put("teacherlist",sel);
        return "/user/teacherlist";
    }

    @RequestMapping("/addUser")
    public String addList(Teacher teacher){
        return "/user/add";
    }
    @RequestMapping("/add")
    public String add(Teacher teacher){
        teacherMapper.add(teacher);
        return "redirect:/teacher/sel";
    }
    @RequestMapping("/delete/{id}")
    public String delete( @PathVariable ("id") int id){
       teacherMapper.delete(id);
       return "redirect:/teacher/sel";
    }

    @RequestMapping("/update")
    public String update(Teacher teacher){
        teacherMapper.update(teacher);
        return "redirect:/teacher/sel";
    }
    @RequestMapping("/edit/{id}")
    public String edit(@PathVariable ("id") int id,ModelMap modelMap){
        modelMap.put("tea",teacherMapper.selTea(id));
        return "/user/update";
    }

}
